<template>
  <div id="article">
    <el-row id="artList" type="flex" justify="space-around" v-for="item of articleList" :key="item.id">
      <el-col>
        <el-row class="art-item">
          <el-card shadow="hover">
            <h5>
              <router-link :to="'/article/' + item.id" tag="span" class="art-title">{{ item.title }}</router-link>
            </h5>
            <el-row class="art-info d-flex align-items-center justify-content-start">
              <div class="art-time">
                <i class="el-icon-time"/>：{{ item.createTime }}
              </div>
              <div class="d-flex align-items-center">
                <i class="iconfont icon-24gf-tags2"/>：
                <span class="art-tag" v-for="tagItem of item.blogTagList" :key="tagItem.id"><el-tag size="mini">{{
                    tagItem.name
                  }}</el-tag></span>
              </div>
            </el-row>
            <el-row class="art-body">
              <div class="side-img hidden-sm-and-down">
                <router-link :to="'/article/' + item.id"><img class="art-banner" :src="item.avatar"></router-link>
              </div>
              <div class="side-abstract">
                <mavon-editor v-model="item.contentMd"
                              :subfield="false"
                              :defaultOpen="'preview'"
                              :editable="false"
                              :toolbarsFlag="false"
                              style="height: 200px;word-break: break-word;"
                />
                <div class="art-more">
                  <router-link :to="'/article/' + item.id" tag="span">
                    <el-button plain>阅读全文</el-button>
                  </router-link>
                  <div class="view"><i class="el-icon-view"/>{{ item.quantity }}</div>
                </div>
              </div>
            </el-row>
            <i class="iconfont icon-top01 star"></i>
          </el-card>
        </el-row>
      </el-col>
    </el-row>
    <div class="block pagination">
      <el-pagination background layout="prev, pager, next" :current-page="currentPage" :page-size="pageSize"
                     :total="total" @current-change="handleCurrentChange"></el-pagination>
    </div>
  </div>
</template>

<script>

import {listArticle} from "@/api";

export default {
  name: "article",
  data() {
    return {
      articleList: [],
      pageSize: 10,
      currentPage: 1,
      total: 0
    }
  },
  created() {
    this.listArticle()
  },
  methods: {
    listArticle() {
      listArticle({pageNum: this.currentPage, pageSize: this.pageSize}).then(res => {
        this.articleList = res.data.results;
        this.currentPage = res.data.pageNum;
        this.total = res.data.total;
      })
    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage;
      this.listArticle();
    }
  }
}
</script>

<style scoped lang="less">
#article {
  margin-top: 20px;
}

.art-item {
  margin-bottom: 20px;
  position: relative;
}

.art-title {
  border-left: 3px solid #F56C6C;
  padding-left: 5px;
  cursor: pointer;
}

.art-title:hover {
  padding-left: 10px;
  color: #409EFF;
}

.art-time {
  margin-right: 20px;
}

.art-body {
  display: flex;
  padding: 10px 0;
}

.side-img {
  height: 150px;
  width: 270px;
  overflow: hidden;
  margin-right: 10px;
}

.art-item .star {
  font-size: 20px;
  width: 60px;
  height: 60px;
  position: absolute;
  color: orangered;
  top: 2%;
  right: 0;
}

img.art-banner {
  width: 100%;
  height: 100%;
  transition: all 0.6s;
}

img.art-banner:hover {
  transform: scale(1.4);
}

.side-abstract {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.art-abstract {
  flex: 1;
  color: #aaa;
}

.art-more {
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.art-more .view {
  color: #aaa;
}

.art-info {
  margin-top: 20px;
  display: flex;
}

.art-tag {
  margin-left: 5px;
}

h5 {
  font-size: 18px;
}
</style>
